package ioReview;

import org.junit.Test;

import java.io.*;

public class PractiseDemo3 {
    @Test
    public void testCopyTxt() throws IOException {
        File srcFile = new File("d:/a.txt");
        // 要copy的文件
        File desFile = new File("d:/b.txt");

        // 输入流
        FileInputStream is = new FileInputStream(srcFile);

        // 输出流对象
        OutputStream os = new FileOutputStream(desFile);

        int hasRead = 0;
        while ((hasRead = is.read()) != -1) {
            //每次写一个字节到b.txt中
            os.write(hasRead);
        }
        System.out.println("写好了");
    }

    @Test
    public void testCopyJpg() throws IOException {
        File srcFile = new File("d:/s.jpg");
        // 要copy的文件
        File desFile = new File("d:/s2.jpg");

        // 输入流
        FileInputStream is = new FileInputStream(srcFile);

        // 输出流对象
        OutputStream os = new FileOutputStream(desFile);

        int hasRead = 0;
        byte[] b = new byte[1024];

        int count = 0;

        while ((hasRead = is.read(b)) != -1) {
            os.write(b, 0, hasRead);
            count++;
        }
    }
}
